﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Internet_Deliver_Therapy.Controllers;
using Internet_Deliver_Therapy.Models;

namespace Internet_Deliver_Therapy.Views.Patient
{
    public partial class Home : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            //Ensure that user login before being able to access the secure pages
            if (Session["Email"] != null)
            {
                string loginUserEmail = Session["Email"].ToString();

                UsersController userController = new UsersController();
                Users loginUser = userController.getUserByEmail(loginUserEmail);
                lblUserFirstName.Text = loginUser.FirstName;
                DateTime newDT = new DateTime();
                string newDT_string = newDT.ToString();
                if (!newDT_string.Equals(loginUser.Lastlogin.ToString()))
                {
                    lblLastLogin.Text = loginUser.Lastlogin.ToString();
                }
                
            }
            else
            {
                Response.Redirect("~/Views/Index/Login.aspx");
            }
            
        }

        protected void logout(object sender, EventArgs e)
        {
            Session.Clear();
            Response.Redirect("~/Views/Index/Login.aspx");
        }
    }
}